package com.glory.good_dark.activity;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.good_dark.R;
import com.glory.good_dark.adapter.PmQueryListAdapter;
import com.glory.good_dark.application.App;
import com.glory.good_dark.entity.ProjectModelEntity;
import com.glory.good_dark.entity.response.BaseEntity;
import com.glory.good_dark.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * FileName: PMQueryActivity
 * Author: XJH
 * Date: 2021/2/23 15:22
 * Description:
 * History:
 */
public class PMQueryActivity extends BaseProjectActivity {
    @BindView(R.id.tvStep)
    TextView tvStep;
    @BindView(R.id.rvPMListView)
    RecyclerView rvPMListView;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    private PmQueryListAdapter mAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_pm_query;
    }

    @Override
    protected void initView() {
        initRecyclerView(rvPMListView,this);
        tvStep.setText(getIntent().getStringExtra("EQPID"));
        mAdapter = new PmQueryListAdapter(null);
        mAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mAdapter.isFirstOnly(true);
        rvPMListView.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        FreeUI_EntityCallBack<BaseEntity<ProjectModelEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<ProjectModelEntity>>
                (new TypeToken<BaseEntity<ProjectModelEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess
                    (final Response<BaseEntity<ProjectModelEntity>> response) {
                if (response.body().isSuccess(getApplicationContext(),getSupportFragmentManager())) {
                    mAdapter.setNewData(response.body().getData().getBody().getPmListInfo());
                }

            }

            @Override
            public void onError
                    (Response<BaseEntity<ProjectModelEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "PDAGetPmHisState");
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("OPERATOR", App.userEntity.getWORKNO());
        map.addProperty("PROCESS", tvStep.getText().toString());
        NetUtils.requestPostNet(App.WEB_URL + "/api/PDA",this,callBack,"PDAGetPmHisState",map);
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        freeUI_titleView.setTitle("PM查询");
        return new FreeUI_AddViewEntity(getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY), llMain);
    }

    @Override
    protected void EQPReplaceSuccess(int tag, String content) {

    }
}
